//
//  ZLOtherViewController.m
//  ZLClient
//
//  Created by lizhu on 2017/5/10.
//  Copyright © 2017年 zhuli. All rights reserved.
//

#import "ZLOtherViewController.h"
#import "ZLLandscapeViewController.h"
#import "ZLRuntimeViewController.h"
#import "ZLRunLoopViewController.h"
#import "ZLKVOViewController.h"

typedef NS_ENUM(NSUInteger,ZLViewControllerType) {
    ZLLandscapeViewControllerType=0,
    ZLRuntimeViewControllerType,
    ZLRunLoopViewControllerType,
    ZLKVOViewControllerType,
    ZLViewControllerTypeCount
};

@interface ZLOtherViewController () <UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *dataArray;
@end

@implementation ZLOtherViewController
#pragma mark - life cycles
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view addSubview:self.tableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma makr - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return ZLViewControllerTypeCount;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID=@"ZLOtherViewControllerCell";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.textLabel.text=[self.dataArray objectAtIndex:indexPath.row];
    }
    return cell;
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.row) {
        case ZLLandscapeViewControllerType:{
            ZLLandscapeViewController *landscapeVC=[[ZLLandscapeViewController alloc] init];
            landscapeVC.hidesBottomBarWhenPushed=YES;
            landscapeVC.title=self.dataArray[ZLLandscapeViewControllerType];
            [self.navigationController pushViewController:landscapeVC animated:YES];
            break;
        }
        case ZLRuntimeViewControllerType:{
            ZLRuntimeViewController *runtimeVC=[[ZLRuntimeViewController alloc] init];
            runtimeVC.hidesBottomBarWhenPushed=YES;
            runtimeVC.title=self.dataArray[ZLRuntimeViewControllerType];
            runtimeVC.view.backgroundColor=[UIColor whiteColor];
            [self.navigationController pushViewController:runtimeVC animated:YES];
            break;
        }
        case ZLRunLoopViewControllerType:{
            ZLRunLoopViewController *runlooVC=[[ZLRunLoopViewController alloc] init];
            runlooVC.hidesBottomBarWhenPushed=YES;
            runlooVC.title=self.dataArray[ZLRunLoopViewControllerType];
            runlooVC.view.backgroundColor=[UIColor whiteColor];
            [self.navigationController pushViewController:runlooVC animated:YES];
            break;
        }
        case ZLKVOViewControllerType:{
            ZLKVOViewController *kvoVC=[[ZLKVOViewController alloc] init];
            kvoVC.hidesBottomBarWhenPushed=YES;
            kvoVC.title=self.dataArray[ZLKVOViewControllerType];
            kvoVC.view.backgroundColor=[UIColor whiteColor];
            [self.navigationController pushViewController:kvoVC animated:YES];
            break;
        }
        default:
            break;
    }
}

#pragma mark - getters and setters
- (NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray=[NSMutableArray array];
        [_dataArray addObject:@"测试横屏"];
        [_dataArray addObject:@"Runtime"];
        [_dataArray addObject:@"RunLoop"];
        [_dataArray addObject:@"KVO Operators"];
    }
    return _dataArray;
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView=[[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
        _tableView.delegate=self;
        _tableView.dataSource=self;
    }
    return _tableView;
}
@end
